Conditions | 1 |
Paths | 1 |
Total Lines | 83 |
Lines | 83 |
Ratio | 100 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | View Code Duplication | var assert = require('chai').assert, |
|
4 | describe('Field', function(){ |
||
5 | |||
6 | it('Create plain', function(){ |
||
7 | assert.instanceOf(new GedcomX.Field(), GedcomX.Field, 'An instance of Field is not returned when calling the constructor with new.'); |
||
8 | assert.instanceOf(GedcomX.Field(), GedcomX.Field, 'An instance of Field is not returned when calling the constructor without new.'); |
||
9 | }); |
||
10 | |||
11 | it('Create with JSON', function(){ |
||
12 | var field = GedcomX.Field({ |
||
13 | id: 'nameField', |
||
14 | type: 'http://gedcomx.org/Name', |
||
15 | values: [ |
||
16 | { |
||
17 | type: 'type', |
||
18 | labelId: 'labelId', |
||
19 | text: 'Text', |
||
20 | confidence: 'http://gedcomx.org/High', |
||
21 | datatype: 'data type', |
||
22 | resource: '#resource' |
||
23 | } |
||
24 | ] |
||
25 | }); |
||
26 | assert.equal(field.getId(), 'nameField'); |
||
27 | assert.equal(field.getType(), 'http://gedcomx.org/Name'); |
||
28 | assert.equal(field.getValues().length, 1); |
||
29 | var fieldValue = field.getValues()[0]; |
||
30 | assert.equal(fieldValue.getType(), 'type'); |
||
31 | assert.equal(fieldValue.getLabelId(), 'labelId'); |
||
32 | assert.equal(fieldValue.getText(), 'Text'); |
||
33 | assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High'); |
||
34 | assert.equal(fieldValue.getDataType(), 'data type'); |
||
35 | assert.equal(fieldValue.getResource(), '#resource'); |
||
36 | }); |
||
37 | |||
38 | it('Build', function(){ |
||
39 | var field = GedcomX.Field() |
||
40 | .setId('nameField') |
||
41 | .setType('http://gedcomx.org/Name') |
||
42 | .addValue({ |
||
43 | type: 'type', |
||
44 | labelId: 'labelId', |
||
45 | text: 'Text', |
||
46 | confidence: 'http://gedcomx.org/High', |
||
47 | datatype: 'data type', |
||
48 | resource: '#resource' |
||
49 | }); |
||
50 | assert.equal(field.getId(), 'nameField'); |
||
51 | assert.equal(field.getType(), 'http://gedcomx.org/Name'); |
||
52 | assert.equal(field.getValues().length, 1); |
||
53 | var fieldValue = field.getValues()[0]; |
||
54 | assert.equal(fieldValue.getType(), 'type'); |
||
55 | assert.equal(fieldValue.getLabelId(), 'labelId'); |
||
56 | assert.equal(fieldValue.getText(), 'Text'); |
||
57 | assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High'); |
||
58 | assert.equal(fieldValue.getDataType(), 'data type'); |
||
59 | assert.equal(fieldValue.getResource(), '#resource'); |
||
60 | }); |
||
61 | |||
62 | it('toJSON', function(){ |
||
63 | var data = { |
||
64 | id: 'nameField', |
||
65 | type: 'http://gedcomx.org/Name', |
||
66 | values: [ |
||
67 | { |
||
68 | type: 'type', |
||
69 | labelId: 'labelId', |
||
70 | text: 'Text', |
||
71 | confidence: 'http://gedcomx.org/High', |
||
72 | datatype: 'data type', |
||
73 | resource: '#resource' |
||
74 | } |
||
75 | ] |
||
76 | }, field = GedcomX.Field(data); |
||
77 | assert.deepEqual(field.toJSON(), data); |
||
78 | }); |
||
79 | |||
80 | it('constructor does not copy instances', function(){ |
||
81 | var obj1 = GedcomX.Field(); |
||
82 | var obj2 = GedcomX.Field(obj1); |
||
83 | assert.strictEqual(obj1, obj2); |
||
84 | }); |
||
85 | |||
86 | }); |